<template>
  <div>
    <el-dialog
      title="新增工单"
      :visible.sync="dialogVisible"
      width="50%"
      @close="offDialogG"
    >
      <!-- 新增 -->
      <div class="form">
        <el-form ref="form" :model="form" label-width="100px" :rules="rules">
          <el-form-item label="设备编号：" prop="innerCode">
            <el-input
              v-model="form.innerCode"
              type="text"
              placeholder="请输入内容"
              maxlength="15"
              show-word-limit
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item label="工单类型：" prop="taskType">
            <el-select v-model="form.taskType" placeholder="请选择" style="width: 300px">
              <el-option label="补货工单" :value="2" />
            </el-select>
          </el-form-item>
          <el-form-item label="补货数量：">
            <el-button type="text" class="el-icon-tickets" @click="addGoods">补货清单</el-button>
          </el-form-item>
          <!-- TODO 暂无人员列表 -->
          <el-form-item label="运营人员：" prop="userName">
            <el-select v-model="form.userName" placeholder="请选择" style="width: 300px" @click.native="getOperation">

              <el-option
                v-for="item in options"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备注：" prop="desc">
            <el-input
              v-model="form.desc"
              type="textarea"
              placeholder="请输入备注(不超过40字)"
              maxlength="40"
              show-word-limit
              :rows="3"
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item />
        </el-form>
      </div>

      <span slot="footer">
        <div class="footer">
          <el-button style="background-color: #fbf4f0;color: #606266;" @click="offDialogG">取 消</el-button>
          <el-button style="background-color: #ff6726;color:#fff" @click="submit">确 定</el-button>
        </div>
      </span>

    </el-dialog>

    <!-- 补货详情 弹窗 -->
    <GoodsList ref="goods" :type="type" />
  </div>
</template>

<script>
import GoodsList from './goodsDetail.vue'

import { getOperationList } from '@/api/lmoperation'

export default {
  name: 'AddDialog',
  components: {
    GoodsList
  },
  props: {
  },
  data() {
    return {
      dialogVisible: false,
      form: {
        innerCode: '', // 设备编号
        taskType: '', // 工单类型
        userName: '', // 运营人员
        desc: '', // 备注
        details: {} // 补货信息
      },
      rules: {
        innerCode: [{ required: true, message: '请输入', trigger: 'blur' }], // 设备编号
        taskType: [{ required: true, message: '请选择', trigger: 'blur' }], // 工单类型
        userName: [{ required: true, message: '请选择', trigger: 'blur' }], // 运营人员
        desc: [{ required: true, message: '请输入', trigger: 'blur' }] // 备注
      },
      // 运营人员集合
      options: [],
      type: ''
    }
  },
  methods: {
    // 弹窗显示
    openDialogK() {
      this.dialogVisible = true
    },
    // 弹窗显示  重新创建
    async showDialog(row) {
      console.log(row)
      this.form.innerCode = row.innerCode
      this.form.userName = row.userName
      this.form.taskType = row.productTypeId
      this.form.desc = row.desc

      const data = await getOperationList(this.form.innerCode)
      this.options = data

      this.dialogVisible = true
    },
    // 弹窗关闭
    async offDialogG() {
      await this.$refs.form.resetFields()
      this.dialogVisible = false
    },
    // 确定 TODO
    async submit() {
      await this.$refs.form.validate()
      console.log(1)
    },
    // 补货详情
    addGoods() {
      // if (!this.form.innerCode) this.$message.warning('请输入设备编号')
      this.$refs.form.validateField('innerCode', () => {

      })
      this.type = 'add'
      // console.log(this.form.innerCode)
      this.$refs.goods.openDialog(this.form.innerCode)
    },
    // 获取运营人员
    async getOperation() {
      console.log(this.form.innerCode)
      const data = await getOperationList(this.form.innerCode)
      this.options = data
    }
  }
}
</script>

<style scoped lang='scss'>
.footer{
  padding-right: 36%;
}
.form{
  padding-left: 50px;
}

</style>
